<template>
  <div>
    <van-nav-bar
      :title="`${$route.query.q} 的搜索接果`"
      left-arrow
      @click-left="$router.go(-1)"
    />
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell v-for="item in searchResult" :key="item.art_id" :title="item.title" 
      @click="$router.push({path:'/search',query:{id:item.aut_id}})" />
    </van-list>
  </div>
</template>

<script>
// 搜索结果列表
import { getSearchList } from './home.js'

export default {
  name: 'searchResult',
  data () {
    return {
      loading: false,
      finished: false,
      list: [],
      searchResult: [],
      page:1
    }
  },
  methods: {
    async onLoad () {
        let res = await getSearchList({
            page: this.page,
            q: this.$route.query.q
        })
        this.page++
        this.searchResult.push(...res.data.data.results)
        this.loading = false
        if (res.data.data.results == 0) {
          this.finished = true
        }
    }
  }
}
</script>

<style></style>
